﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WTwitter.Model.UserData;
using WTwitter.Model.Twitter.Json;
using WTwitter.Model.Twitter.Utility;

namespace WTwitter.ViewModel {
	sealed public class AccountInfoViewModel : ClosableViewModelBase {
		private AuthInfo _info;
		private Hash _hash;
		private User _user;

		public AccountInfoViewModel(AuthInfo info) 
			: base("アカウント情報") {
			_info = info;
		}

		public void GetInformation() {
			_user = AccountMethod.VerifyCredential(_info);
			_hash = AccountMethod.RateLimitStatus(_info);
		}

		public string AccountUserName {
			get { return _user.ScreenName; }
		}

		public int RemainingHits {
			get { return _hash.RemainingHits; }
		}

		public int HourlyLimit {
			get { return _hash.HourlyLimit; }
		}

		private DateTime? _resetTime;
		public DateTime ResetTime {
			get {
				if (!_resetTime.HasValue) {
					_resetTime = DateTimeConverter.StringToDateTime(_hash.ResetTimeString);
				}
				return _resetTime.Value;
			}
		}

		public string ResetTimeDisplayString {
			get {
				return ResetTime.ToLocalTime().ToString("yyyy/MM/dd HH:mm");
			}
		}
	}
}
